package com.zimi.controller;

import com.zimi.service.RegistryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Api("注册用户")
@Controller
@RequestMapping("reset-password")
public class ResetPasswordApi {

    @Autowired
    private RegistryService registryService;


    @PostMapping("sendVerifiNumber")
    @ApiOperation("发送验证码")
    @ResponseBody
    public Object sendVerifiNumber(HttpServletRequest request, HttpServletResponse response) {

        String[] ma = request.getParameterValues("phone");
        registryService.forPasswordSendVerification(ma[0]);

        Map map = new HashMap();
        map.put("code", 0);
        return map;
    }

    @PostMapping("verification")
    @ApiOperation("确认验证码")
    @ResponseBody
    public Object verification(HttpServletRequest request, HttpServletResponse response) {

        String[] ma = request.getParameterValues("verifyCode");
        registryService.forPasswordVerify(ma[0]);

        Map map = new HashMap();
        map.put("code", 0);
        return map;
    }

    @GetMapping("page1")
    public String reg() {
        return "resetPassword";
    }
}
